package com.useeinfo.framework.sugar.data;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

/**
 * Created by sillyboy.
 * Time: 2018/10/16 15:25
 */
public class TableResultData {

    public static JSONObject Rsult(Integer errcode, String errmsg, Integer total, JSONArray rows) {
        JSONObject result = new JSONObject();
        result.put("errcode", errcode);
        result.put("errmsg", errmsg);
        result.put("total", total);
        result.put("rows", rows);
        return result;
    }

    public static JSONObject Rsult(Integer total, Integer pageNum, Integer pageSize, JSONArray rows) {
        JSONObject result = new JSONObject();
        Integer last = total % pageSize > 0 ? total / pageSize + 1 : (total / pageSize == 0 ? 1 : total / pageSize);
        result.put("pageNo", pageNum);
        Integer prev = pageNum > 1 ? pageNum - 1 : 1;
        Integer next = pageNum.equals(last) ? pageNum : pageNum + 1;
        result.put("prev", prev);
        result.put("pageSize", pageSize);
        result.put("next", next);
        result.put("list", rows);
        result.put("first", 1);
        result.put("count", total);
        result.put("last", last);
        return result;
    }
    public static JSONObject jqResult(Integer total, Integer pageNum, Integer pageSize, JSONArray rows) {
        JSONObject result = new JSONObject();
        result.put("page", pageNum);
        result.put("records", pageSize);
        result.put("rows", rows);
        result.put("total", total);
        return result;
    }

    public static JSONObject NULL() {
        return Rsult(0, "ok", 0, new JSONArray());
    }

}
